package com.ice.work.moment.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.honeybee.cloud.framework.common.page.Page;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.honeybee.cloud.framework.mybatis.page.PageMapper;
import com.honeybee.cloud.framework.oauth.controller.BaseController;
import com.ice.work.moment.facade.user.controller.role.IRoleController;
import com.ice.work.moment.facade.user.dto.RoleDTO;
import com.ice.work.moment.facade.user.mapper.ParamConvertMapper;
import com.ice.work.moment.facade.user.mapper.RoleConvertMapper;
import com.ice.work.moment.facade.user.model.Role;
import com.ice.work.moment.facade.user.param.PageRoleParam;
import com.ice.work.moment.facade.user.request.PageRoleRequest;
import com.ice.work.moment.facade.user.vo.RoleVO;
import com.ice.work.moment.user.service.role.IRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 角色
 * @Author DELL
 * @Create 2019-02-11
 * @Since 1.0.0
 */
@RestController
@Slf4j
public class RoleController extends BaseController implements IRoleController {

    @Autowired
    private IRoleService roleService;

    @Override
    public ResponseEntity<Page<RoleVO>> pageRole(PageRoleRequest request, Long page, Long size) {
        IPage<Role> iPage = PageMapper.INSTANCE.pageInfo(page, size);
        PageRoleParam param = ParamConvertMapper.INSTANCE.toParam(request);
        Page<RoleDTO> resourceDTOPage = roleService.page(iPage, param);
        Page<RoleVO> voPage = RoleConvertMapper.INSTANCE.toVO(resourceDTOPage);
        return ResponseEntity.ok(voPage);
    }
}
